package com.lefevre.cms.bean.redEnvelope;

import com.baomidou.mybatisplus.annotation.Version;
import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 发红包
 *
 * @author Lefevre
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("give_red_envelope")
@Entity
@Table(name = "give_red_envelope", indexes = {@Index(name = "give_red_envelope_1_idx", columnList = "bindTopicId"), @Index(name = "giveRedEnvelope_2_idx", columnList = "userId,giveTime")})
public class GiveRedEnvelope implements Serializable {
    private static final long serialVersionUID = -3738039930994089472L;

    @Id
    @Column(length = 32)
    @TableId(type = IdType.INPUT)
    private String id;

    /**
     * 发红包的用户Id
     **/
    @TableField("userId")
    private Long userId;

    /**
     * 发红包的用户名称
     **/
    @Transient
    @TableField(exist = false)
    private String userName;

    /**
     * 发红包的用户呢称
     **/
    @Transient
    @TableField(exist = false)
    private String nickname;

    /**
     * 发红包的用户头像路径
     **/
    @Transient
    @TableField(exist = false)
    private String avatarPath;

    /**
     * 发红包的用户头像名称
     **/
    @Transient
    @TableField(exist = false)
    private String avatarName;

    /**
     * 类型 10.个人定向红包、20.公共随机红包(随机金额)、30.公共定额红包(固定金额)
     **/
    @TableField("`type`")
    private Integer type = 10;

    /**
     * 总金额
     **/
    @Column(precision = 12, scale = 2)
    @TableField(value = "totalAmount", numericScale = "2")
    private BigDecimal totalAmount;

    /**
     * 单个红包金额 type=30时有值
     **/
    @Column(precision = 12, scale = 2)
    @TableField(value = "singleAmount", numericScale = "2")
    private BigDecimal singleAmount;

    /**
     * 发放数量
     **/
    @TableField("giveQuantity")
    private Integer giveQuantity;

    /**
     * 祝福语
     **/
    @Column(length = 150)
    @TableField("wishes")
    private String wishes;

    /**
     * 绑定话题Id  -1表示空值
     **/
    @TableField("bindTopicId")
    private Long bindTopicId = -1L;

    /**
     * 绑定话题标题
     **/
    @Transient
    @TableField(exist = false)
    private String bindTopicTitle;

    /**
     * 分配金额组 结构：List<BigDecimal>的JSON格式
     **/
    @Lob
    @TableField("distributionAmountGroup")
    private String distributionAmountGroup;

    /**
     * 抢到红包的用户Id组  结构：删除最后一个逗号再加上中括号可组成List<Long>的JSON格式
     **/
    @Lob
    @TableField("grabRedEnvelopeUserIdGroup")
    private String grabRedEnvelopeUserIdGroup = "[";

    /**
     * 剩余数量
     **/
    @TableField("remainingQuantity")
    private Integer remainingQuantity;

    /**
     * 中止领取红包后返还金额
     **/
    @Column(precision = 12, scale = 2)
    @TableField(value = "refundAmount", numericScale = "2")
    private BigDecimal refundAmount;

    /**
     * 发放时间
     **/
    @TableField("giveTime")
    @Temporal(TemporalType.TIMESTAMP)
    private Date giveTime = new Date();

    /**
     * 访问用户是否已拆本红包
     **/
    @Transient
    @TableField(exist = false)
    private boolean accessUserUnwrap = false;

    /**
     * 版本号
     **/
    @Version
    private Integer version = 0;

}
